package jay.home.bet.dao.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jay.home.bet.dao.AccountDao;
import jay.home.bet.domain.User;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao
{

	public void deleteUser(User user) throws DataAccessException
	{
		getSqlMapClientTemplate().delete("deleteUser", user );
	}

	public User getUser(String username) throws DataAccessException
	{
		HashMap map = new HashMap();
		map.put("username", username);
		
		return (User)getSqlMapClientTemplate().queryForObject("getUser", map);
	}

	public List<User> getAliveUsers(int page, int range) throws DataAccessException
	{
		HashMap map = new HashMap();
		map.put("alive", true);
		return (List<User>)getSqlMapClientTemplate().queryForList("getUser", map, (page - 1) * range, range);
	}
	
	public List<User> getAllUsers(int page, int range) throws DataAccessException
	{
		return (List<User>)getSqlMapClientTemplate().queryForList("getUser", null, (page - 1) * range, range);
	}

	public void insertUser(User user) throws DataAccessException
	{
		getSqlMapClientTemplate().insert("insertUser", user);
	}

	public void updateUser(User user) throws DataAccessException
	{
		getSqlMapClientTemplate().update("updateUser", user);
	}
}